package com.supreme.studyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.studyserver.service.ManagementService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "jvm")
public class JvmInfoController {

    @Resource
    private BeanFactory beanFactory;

    @GetMapping(value = "getMemoryInfo")
    public AjaxResp getMemoryMXBeanInfo() {
        ManagementService managementService = beanFactory.getBean(ManagementService.class);
        managementService.getMemoryMXBeanInfo();
        return AjaxResp.instance();
    }

    @GetMapping(value = "getSystemInfo")
    public AjaxResp getOperatingSystemMXBeanInfo() {
        ManagementService managementService = beanFactory.getBean(ManagementService.class);
        managementService.getOperatingSystemMXBeanInfo();
        return AjaxResp.instance();
    }

    @GetMapping(value = "getThreadInfo")
    public AjaxResp getThreadInfo() {
        ManagementService managementService = beanFactory.getBean(ManagementService.class);
        managementService.getThreadMXBeanInfo();
        return AjaxResp.instance();
    }

    @GetMapping(value = "getOtherInfo")
    public AjaxResp getOtherInfo() {
        ManagementService managementService = beanFactory.getBean(ManagementService.class);
        managementService.getOtherManagementInfo();
        return AjaxResp.instance();
    }
}
